package logic

import (
	"context"
	"gorm.io/gorm"
	"hire/models/mysql"

	"hire/hirerpc/hirerpc"
	"hire/hirerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PublishUpdatesLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPublishUpdatesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PublishUpdatesLogic {
	return &PublishUpdatesLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PublishUpdatesLogic) PublishUpdates(in *hirerpc.PublishUpdatesRequest) (*hirerpc.PublishUpdatesResponse, error) {
	// todo: add your logic here and delete this line
	var publish mysql.Publish
	mysql.DB.Debug().Where("id=?", in.PublishId).Find(&publish)
	publish = mysql.Publish{
		Model:   gorm.Model{ID: uint(in.PublishId)},
		Money:   float64(in.Money),
		Request: in.Request,
	}
	return &hirerpc.PublishUpdatesResponse{
		PublishId: int64(publish.ID),
	}, nil
}
